package com.zood.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zood.dao.ActivityDao;
import com.zood.dao.StoneDao;
import com.zood.domain.activity;
import com.zood.domain.stone;
import com.zood.service.activityService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;

@Service
public class activityServiceImpl extends ServiceImpl<ActivityDao, activity> implements activityService {

    @Autowired
    private ActivityDao bookDao;

    @Override
    public boolean saveBook(activity book) {
        return bookDao.insert(book) > 0;
    }

    @Override
    public boolean modify(activity book) {
        return bookDao.updateById(book) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return bookDao.deleteById(id) > 0;
    }

    @Override
    public IPage<activity> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,null);
        return page;
    }

    @Override
    public IPage<activity> getPage(int currentPage, int pageSize, activity book) {
        LambdaQueryWrapper<activity> lqw = new LambdaQueryWrapper<activity>();
        //       lqw.like(Strings.isNotEmpty(book.getVid()),activity::getVid,book.getVid());
        lqw.like(Strings.isNotEmpty(book.getAname()), activity::getAname,book.getAname());
        lqw.like(Strings.isNotEmpty(book.getAdescription()), activity::getAdescription,book.getAdescription());
        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,lqw);
        return page;
    }

}
